var fs = require("fs");
var a = fs.readFileSync('input1.json');
let read = JSON.parse(a)
read.forEach(element => {
    let index = 0
    for (; index < element.length; ) {
        let tmp_admin2 = element[index]["Adm2_EN"]
        let gudingindex = index
        element[gudingindex].children = []
        
        console.log("这个二级行政区",element[index]["Adm2_EN"],"的内部长度是",element.length)
        while (index < element.length ) {
            if(tmp_admin2 === element[index]["Adm2_EN"] ){
                element[gudingindex].children.push(JSON.parse(JSON.stringify(element[index])));
                index++;
                console.log(index)
            }else{
                break
            }
           
        }
        
    }

});


fs.writeFile('input2.json', JSON.stringify(read), function (err) {
    if (err) {
        return console.error(err);
    }
    console.log("数据写入成功！");
    console.log("--------我是分割线-------------")
    console.log("读取写入的数据！");

});
